# -*- coding: utf-8 -*-
# © 2018 QYT Technology
# Authored by: Zhao Xingtao (zxt50330@gmail.com)
from decimal import Decimal

from flask.json import JSONEncoder
import datetime


class CustomJSONEncoder(JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime.datetime) or isinstance(obj, datetime.date):
            return obj.isoformat()
        elif isinstance(obj, Decimal):
            return float(str(obj))
        try:
            return super(CustomJSONEncoder, self).default(obj)
        except TypeError:
            return str(obj)